package com.itqf.quartz;

import com.itqf.job.LogJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * projectName: logandquratz2103
 *
 * @author: 赵伟风
 * time: 2021/7/6 15:03
 * description: 每晚八点到10点 每10秒执行一次!
 */
public class SimperUse8_10 {


    public static void main(String[] args) throws SchedulerException {

        //1.创建jobdetail
        JobDetail jobDetail = JobBuilder.newJob(LogJob.class).build();

        //2.创建simpleTrigger
        //指定间隔的时间  15个小时后
        Date start = DateBuilder.futureDate(15, DateBuilder.IntervalUnit.HOUR);
        Date end = DateBuilder.futureDate(16, DateBuilder.IntervalUnit.HOUR);

        //设置间隔是时间节点
        start = DateBuilder.dateOf(15, 23, 0);
        end = DateBuilder.dateOf(15, 25, 0);


        SimpleTrigger simpleTrigger =
                TriggerBuilder.newTrigger().startAt(start).endAt(end).withSchedule(
                        SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).repeatForever()).build();

        //3.创建scheduler
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        //4.设置job/trigger
        scheduler.scheduleJob(jobDetail, simpleTrigger);
        //5.启动scheduler
        scheduler.start();

    }

}
